package com.ydlclass;

/**
 * RecursiveBinaryTree
 *
 * @author byc
 * @date 2021-12-28
 */
public class RecursiveBinaryTree {

    private static class Node{
        Integer data;
        Node left;
        Node right;

        public Node(Integer data) {
            this.data = data;
        }
    }

    /**
     * 递归方法
     *
	 * @param node node
     * @return void
     */
    private static void recursive(Node node){
        if (node == null){
            return;
        }
        recursive(node.left);
        recursive(node.right);

    }

    /**
     * 遍历方法 先 中 后
     *
     * @param node node
     * @return void
     */
    private static void preOrder(Node node){
        if (node == null){
            return;
        }
        //先序
        System.out.println(node.data);
        preOrder(node.left);
        //中序
        //System.out.println(node.data);
        preOrder(node.right);
        //后序
        //System.out.println(node.data);
    }

    public static void main(String[] args) {
        Node root = new Node(1);
        root.left = new Node(2);
        root.right = new Node(3);
        root.left.left = new Node(4);
        root.left.right = new Node(5);
        root.right.left = new Node(6);
        root.right.right = new Node(7);

        preOrder(root);

    }

}
